﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace WebCalendar.Models
{
    public class AppointmentRequest 
    {               
        public int ID {get; set;}                   
        public Guid URLCode  {get; set;}
        public string RequestorName {get; set;}
        public string RequestorPhoneNumber {get; set;}
        public string RequestorEmail   {get; set;}
        public UserProfile RequestorUserProfile {get; set;}
        public Calendar Calendar  {get; set;}
        public DateTime RequestDate   {get; set;}
        public string Title { get; set; }
        public string Description { get; set; }
        public DateTime RequestedStartDate  {get; set;}
        public DateTime? RequestedEndDate {get; set;}
        public bool IsAllDay { get; set; }
        public DateTime? AcceptDate { get; set; }
        public DateTime? RefuseDate { get; set; }
    }


    public class PersonalEntry
    {
        public int ID { get; set; }
        public Entry EntryBase { get; set; }
        public Category Category { get; set; }
    }

    public class Category
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Color { get; set; }
        public virtual ICollection<PersonalEntry> Entries { get; set; }
        public UserProfile User { get; set; }

        public Category()
        {
            Entries = new List<PersonalEntry>();
        }
    }

    public class EntryFilter 
    {
        public int ID { get; set; }
        public PersonalEntry Entry { get; set; }
        public bool Visible { get; set; }
        public Calendar Calendar { get; set; }
    }

    public abstract class Role
    {
        public int ID { get; set; }
        public Calendar Calendar { get; set; }
        public UserProfile User { get; set; }

        public abstract bool EditCalendar();
        public abstract bool DeleteCalendar();
        public abstract bool ManageRoles();
        public abstract string RoleName();
    }

    public class OwnerRole : Role
    {
        public override bool EditCalendar()
        {
            return true;
        }

        public override bool DeleteCalendar()
        {
            return true;
        }

        public override bool ManageRoles()
        {
            return true;
        }

        public override string RoleName()
        {
            return "Owner";
        }
    }

    public class EditorRole : Role
    {
        public override bool EditCalendar()
        {
            return true;
        }

        public override bool DeleteCalendar()
        {
            return false;
        }

        public override bool ManageRoles()
        {
            return false;
        }

        public override string RoleName()
        {
            return "Editor";
        }
    }

    public class MemberRole : Role
    {
        public override bool EditCalendar()
        {
            return false;
        }

        public override bool DeleteCalendar()
        {
            return false;
        }

        public override bool ManageRoles()
        {
            return false;
        }

        public override string RoleName()
        {
            return "Member";
        }
    }

    public class Calendar
    {
        public int ID { get; set; }
        [RequiredAttribute]
        public string Name { get; set; }
        public bool IsPublic { get; set; }
        public virtual ICollection<EntryFilter> EntryFilters { get; set; }
        public virtual ICollection<Role> CalendarRoles { get; set; }
        
        public Calendar()
        {
            CalendarRoles = new List<Role>();
            EntryFilters = new List<EntryFilter>();
        }
    }
}